package com.googlecode.curvedmetromaps.core.logic.forcedriven;

import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;

import com.googlecode.curvedmetromaps.core.model.MetroStation;

/**
 * Constraint S6: maximizes angular resolution.
 */
public class ForceS7 extends ForceSubsystem {

	ForceS7(ForceSystem system) {
		super(system);
	}

	void applyForces(int delta) {
		for (MetroStation m : system.metroMap.stations) {
			Body b = system.stationBodies[m.id];
			Vec2 p = b.getPosition();
			Vec2 geo = new Vec2(m.geoX, m.geoY);

			Vec2 direction = p.sub(geo);
			float len = direction.normalize();
			double f = ForceConstants.S2_ATTRACT1
					* Math.log(len / ForceConstants.S2_ATTRACT2);

			direction.mulLocal((float) f);

			b.applyForceToCenter(direction);
		}
	}
}
